Week 11: Input devices

Explanation of Protocol I2C

Because I2C utilizes addressing, it enables the control of multiple slaves from a single master. With a 7-bit address, there are 128 (2^7) unique addresses available. Although less common, employing 10-bit addresses offers 1,024 (2^10) unique addresses. To link multiple slaves to a sole master, connect them in the following configuration, utilizing 4.7K Ohm pull-up resistors to connect the SDA and SCL lines to Vcc


I2C combines the advantages of SPI and UARTs, allowing for the connection of multiple slaves to a single master, akin to SPI, and enabling multiple masters to control single or multiple slaves. This flexibility proves invaluable for scenarios such as logging data from multiple microcontrollers to a single memory card or displaying text on a shared LCD screen.

  1. With only two wires—SDA (Serial Data) for transmitting and receiving data.
  2. SCL (Serial Clock) for the clock signal—I2C facilitates serial communication, transmitting data bit by bit along the SDA line.

Synchronous like SPI, I2C synchronizes the transmission and sampling of bits using a shared clock signal controlled by the master.

Start programing PCB

  1. Define Communication Protocols:
    • Xiao RF2040 to Receiver Xiao RF2040: I2C communication.
    • Xiao RF2040 to Receiver Xiao RF2040: I2C communication.

    • or

    • Xiao RF2040 to Attiny45: Serial : I2C communication.
    • Attiny45 to Xiao RF2040: I2C communication.
  2. Set Up Hardware Connections:
    • Xiao RF2040 to Made PCB: Connect I2C pins (SDA/SCL).
    • Xiao RF2040 to Made PCB:Connect I2C pins (SDA/SCL).
    • Xiao RF2040 to Made PCB:Connect I2C pins (SDA/SCL).

    • or

    • Attiny45 to Xiao RF2040: Connect I2C pins (SDA/SCL).
  3. Implement Firmware/Software:
    • ESP32: Then we have to create the code to act as the writer/sender. Utilize the ESP32's UART library to send data to both the Xiao RF2040 and Attiny45.
    • Xiao RF2040: Also write a code to receive data from the ESP32 via UART. Implement logic to respond to received data.
    • Attiny45: And write a code to receive data from the ESP32 via UART. Implement logic to control the 10 Neopixels based on received data.
    • Attiny45 to Xiao RF2040: Finally write a code to act as an I2C slave. Implement logic to receive data from the Attiny45 and control the LEDs accordingly.
  4. Testing and Debugging:
    • Test each component individually to ensure it functions correctly.
    • Test the entire system to verify intercommunication between all devices.
    • Debug any issues encountered during testing, such as communication errors or unexpected behavior.
  5. Load the code

  6. Optimization and Refinement
    • Optimize the code for each device to improve performance and reduce resource usage.
    • Refine the communication protocols if necessary to enhance reliability and efficiency.
  7. Final result